package at.fhhagenberg.mcm09.elevator.controlTest;


import java.rmi.RemoteException;

import org.easymock.EasyMock;

import sqelevator.IElevator;

import at.fhhagenberg.mcm09.elevator.control.*;
import at.fhhagenberg.mcm09.elevator.control.ElevatorControl.ControlMode;

import at.fhhagenberg.mcm09.elevator.model.RequestModel;
import at.fhhagenberg.mcm09.elevator.model.StopRequest;
import junit.framework.TestCase;


public class ElevatorControlTest extends TestCase {
	
	public void testHandleRequestAutomatic() throws RemoteException{


		IElevator elevatorMock = EasyMock.createMock(IElevator.class);
		ElevatorAdapter adapter = new ElevatorAdapter(elevatorMock);
		EventGenerator gen = new EventGenerator(adapter);
		ElevatorControl ctrl = new ElevatorControl(elevatorMock, adapter, gen);
		
		RequestModel mdl = new RequestModel();
		StopRequest sr1 = new StopRequest(2);
		StopRequest sr2 = new StopRequest(8);
		/*
		mdl.addRequest(sr1);
		mdl.addRequest(sr2);
		
		ctrl.setControlMode(ControlMode.AUTOMATIC);

		
		elevatorMock.setTarget(0,2);
		EasyMock.expect(elevatorMock.getTarget(0)).andReturn(2);
		EasyMock.replay(elevatorMock);
		
		ctrl.handleRequest(mdl);
		int t_real= ctrl.getNextFloor();
		assertEquals(2, t_real);
		
		EasyMock.verify(elevatorMock);
		*/
	}

	public void testHandleRequestManualMode() throws RemoteException{
		
		IElevator elevatorMock = EasyMock.createMock(IElevator.class);
		ElevatorAdapter adapter = new ElevatorAdapter(elevatorMock);
		EventGenerator gen = new EventGenerator(adapter);
		ElevatorControl ctrl = new ElevatorControl(elevatorMock, adapter, gen);
		
		RequestModel mdl = new RequestModel();
		StopRequest sr1 = new StopRequest(2);
		StopRequest sr2 = new StopRequest(8);
		
		mdl.addRequest(sr1);
		mdl.addRequest(sr2);
		
		ctrl.setControlMode(ControlMode.MANUAL);
		EasyMock.expect(elevatorMock.getTarget(0)).andReturn(0);
		EasyMock.replay(elevatorMock);
		ctrl.handleRequest(mdl);
		int t_real = ctrl.getNextFloor();
		assertEquals(0, t_real);
		EasyMock.verify(elevatorMock);
	}
	
//	public void testHandleRequestAutomatic2() throws RemoteException{
//		
//		IElevator elevatorMock = EasyMock.createMock(IElevator.class);
//		ElevatorAdapter adapter = new ElevatorAdapter(elevatorMock);
//		ElevatorControl ctrl = new ElevatorControl(elevatorMock, adapter);
//		
//		RequestModel mdl = new RequestModel();
//		StopRequest sr1 = new StopRequest(3);
//		StopRequest sr2 = new StopRequest(8);
//		
//		mdl.addRequest(sr1);
//		mdl.addRequest(sr2);
//		
//		ctrl.setControlMode(ControlMode.AUTOMATIC);
//
//		
//	}

}
